home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c,comp.std.c
- Subject: Re: Trouble with file return code.
- Date: 17 Jan 1996 15:02:06 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Jan17080206@qcd.lanl.gov>
- References: <tcpnntpd.16.1.10.20.22.42.2781597121.333610@the-fix.sos.on.ca>
- <4d3h96$9fl@news.iag.net> <DLAv0C.GqF@thinkage.on.ca>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: atbowler@thinkage.on.ca's message of Wed, 17 Jan 1996 00:36:12 GMT
-
- --text follows this line--
-
- Note crosspost to comp.std.c.
-
- In article <DLAv0C.GqF@thinkage.on.ca> atbowler@thinkage.on.ca (Alan
- Bowler) writes:
- <snip>
- In article <4d3h96$9fl@news.iag.net> jatmon@iag.net (John R Buchan) writes:
- >
- > /* Of course, you'll want to do better i/o testing, but basically */
- > while( fread(buf, sizeof(buf), 1, ptr) == 1)
-
- I know you covered yourself with a disclaimer, but this one is very
- dicy. If fread get an EOF part way though the "sizeof buf" bytes
- it may return 0 or 1. (does the library round up or down?).
-
- `The fread function returns the number of elements succesfully
- read'. Do you consider reading less than the number of bytes as a
- successful read of an element?
-
- I suggest
-
- while(sizeof buf == (count = fread(buf, 1, sizeof(buf), ptr))) {
- /* play with the record */
- }
- if (0 != count)
- error("last record was incomplete. and had only %d bytes", count);
-
- I watch this one carefully because we bit a set of users once when
- we changed the round up/down choice in our library.
-
- Is `rounding up' ANSI conformant?
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-